package com.julius.design.pattern.filter;

import java.util.List;

/**
 * <p>
 *      Or条件
 * </p>
 */
public class OrFilter implements Filter{

    private final Filter filter;

    private final Filter otherFilter;


    public OrFilter(Filter filter,Filter otherFilter) {
        this.filter = filter;
        this.otherFilter = otherFilter;
    }


    @Override
    public List<Person> filter(List<Person> personList) {
        List<Person> list = this.filter.filter(personList);

        List<Person> otherList = otherFilter.filter(personList);

        for (Person person : list) {
            if (otherList.contains(person)) {
                continue;
            }
            otherList.add(person);
        }
        return otherList;
    }
}
